﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Business;
using Foundation;
using RPGSoundmixer.TreeNodes;

namespace RPGSoundmixer.SoundSuiteConfiguration {
    /// <summary>
    /// Der Interaktionsteil der SoundSuiteConfigurtion View
    /// </summary>
    public partial class SoundSuiteConfigurationView : Form, ISoundSuiteConfigurationView {
        private SoundSuiteConfigurationPresenter presenter;
        private IDataHandler handler; 

        /// <summary>
        /// Die aktuell angezeigt SoundSuite
        /// </summary>
        public SoundSuite SoundSuite {
            get {
                throw new NotImplementedException();
            }
            set {
                throw new NotImplementedException();
            }
        }


        public SoundSuiteConfigurationView()  {
            InitializeComponent();
            if (!this.DesignMode) {
                this.presenter = new SoundSuiteConfigurationPresenter(this);
                this.handler = DataHandler.GetInstance();
                this.handler.PropertyChanged += new PropertyChangedEventHandler(handler_PropertyChanged);
                this.deleteEffectGroup.Click += new EventHandler(deleteEffectGroup_Click);
                this.newEffectGroup.Click += new EventHandler(newEffectGroup_Click);
                this.createNewEffect.Click += new EventHandler(createNewEffect_Click);
                this.deleteEffect.Click += new EventHandler(deleteEffect_Click);
            }
        }

        void deleteEffect_Click(object sender, EventArgs e) {
            throw new NotImplementedException();
        }

        void createNewEffect_Click(object sender, EventArgs e) {
            EffektCreateView view = new EffektCreateView(((EffektGroupTreeWrapper) this.treeSoundSuite.SelectedNode).EffektGroup.FreeKeys);
            view.ShowDialog(); 
        }

        void newEffectGroup_Click(object sender, EventArgs e) {
            if (treeSoundSuite.SelectedNode.GetType().Equals(typeof(SoundSuiteTreeWrapper))) {
                (new EffektGroupCreateView(((SoundSuiteTreeWrapper)treeSoundSuite.SelectedNode).Suite.freeKeys)).ShowDialog();
            }
            else {
                MessageBox.Show(((TreeNode)treeSoundSuite.SelectedNode).Text);
            }
        }

        void deleteEffectGroup_Click(object sender, EventArgs e) {
            MessageBox.Show(((TreeNode)treeSoundSuite.SelectedNode).Text); 
        }

       

        void handler_PropertyChanged(object sender, PropertyChangedEventArgs e) {
            if (e.PropertyName.Equals("CurrentSoundSuite")) {
                this.treeSoundSuite.Nodes.Clear(); 
                SoundSuite currentSuite = handler.GetCurrentSoundSuite();
                SoundSuiteTreeWrapper rootTree = new SoundSuiteTreeWrapper(currentSuite);
                rootTree.ContextMenuStrip = this.contextMenuStrip1;
                foreach (EffektGroup group in rootTree.Suite.EffektGroups) {
                    EffektGroupTreeWrapper groupNode = new EffektGroupTreeWrapper(group);
                    groupNode.ContextMenuStrip = this.EffektMenuStrip2; 
                    rootTree.Nodes.Add(groupNode);
                }                
                this.treeSoundSuite.Nodes.Add(rootTree);
            }
        }

        private void SoundSuiteConfigurationView_Load(object sender, EventArgs e) {

        }



        
    }
}
